home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
53627
/
53627.xpi
/
chrome
/
content
/
mobilize
/
mobilize.js
next >
Wrap
Text File
|
2010-01-15
|
4KB
|
104 lines
/*
* Mobilize Copyright (C) 2009 Attila Csipa
*
* Code relased under the GNU General Public Licence (GPL), version 2 or later
*
* http://www.gnu.org/licenses/gpl.html
*
* URI parser segment based on
* parseUri 1.2.2
* (c) Steven Levithan <stevenlevithan.com>
* MIT License
*/
var Mobilize = {
DEBUG_MODE : true,
log : function(msg) {
if (!this.DEBUG_MODE)
{
return;
}
if (!this.consoleService)
this.consoleService = Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService);
this.consoleService.logStringMessage('Mobilize: ' + msg);
},
bleep : function(msg) {
alert(msg)
},
parseUri : function (str) {
var o = {
strictMode: false,
key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
q: {
name: "queryKey",
parser: /(?:^|&)([^&=]*)=?([^&]*)/g
},
parser: {
strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
}
}
m = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
uri = {},
i = 14;
while (i--) uri[o.key[i]] = m[i] || "";
uri[o.q.name] = {};
uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
if ($1) uri[o.q.name][$1] = $2;
});
return uri;
},
switchuri : function(uri) {
if (String(uri.substring(0,5))=="about") {
Mobilize.bleep("about can't be switched");
return
}
uriobj = Mobilize.parseUri(uri)
if (uriobj.host.search('www.google.com') >= 0 && uri.search ('dc=mgcgo') < 0) { // the Google treatment
uri = uriobj.protocol + "://m.google.com/go"
// if (uriobj.host == 'www.google.com')
// uri = uri.replace('\/\/www.google.com', '//mobile.google.com/go');
} else if (uriobj.host.search('amazon.com') >= 0 && uri.search('/gp/aw/') < 0) { // the Amazon treatment
uri = uri.replace('amazon.com', 'amazon.com/gp/aw/h.html?');
} else if (uriobj.host.search('www.facebook.com') >= 0 ) {
uri = uri.replace('www.facebook', 'touch.facebook');
} else if (uriobj.host.search('slashdot.org') >= 0 ) {
uri = uri.replace('slashdot.org', 'slashdot.org/palm/?');
} else if (uriobj.host.search('fandango.com') >= 0 ) {
uri = uri.replace('www.fandango', 'mobile.fandango');
} else if (uriobj.host.search('wikipedia.org') >= 0 ) {
uri = uri.replace('en.wikipedia.org', 'mobile.wikipedia.org');
uri = uri.replace('www.wikipedia.org', 'mobile.wikipedia.org');
uri = uri.replace(/\/wiki\//, '/transcode.php?go=');
// http://m.technewstube.com/site/ars-technica/
} else if (uriobj.host.search('m.') == 0) {
uri = uri.replace('\/\/m.', '//www.');
} else {
if (uriobj.host.search('www.') > 0) {
uri = uri.replace(/\/\/www./, '//m.');
} else {
uri = uri.replace(/\/\//,'//m.');
}
}
window.content.location.replace(uri);
// alert(uri);
// var xmlhttp = new XMLHttpRequest();
// xmlhttp.open("GET", uri, true);
// xmlhttp.send(null)
}
}